package com.course.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.course.bean.FeedbackTo;
import com.course.delegate.FeedbackMgrDelegate;
import com.course.exception.DataNotFoundException;
import com.course.formbean.FeedBackFormBean;
import com.course.util.UtilConstants;



public class ViewAllFeedbacksAction extends HttpServlet {


	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
                   doPost(request, response);
                   }
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		FeedBackFormBean fb=new FeedBackFormBean();
		Map map=request.getParameterMap();
	try {
		BeanUtils.populate(fb, map);
	} catch (IllegalAccessException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	} catch (InvocationTargetException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
		
		
	}
        String path="";
        Vector<FeedbackTo> feedbackInfo=null;

	  try{
		  try{
		  feedbackInfo= new FeedbackMgrDelegate().getFeedBack();
		  }catch (DataNotFoundException e) {
			e.printStackTrace();
		}
		  
		  System.out.println("in Action class vcb..........."+feedbackInfo);
		  if(!feedbackInfo.isEmpty()){
			  request.setAttribute("Feedbackvector", feedbackInfo);
			  request.setAttribute("status", UtilConstants._VIEW_ALL_FEEDBACKS);
			  path=UtilConstants._VIEW_ALL_FEEDBACK;
			 }
		  else {
			  request.setAttribute("status", UtilConstants._ALL_FEEDBACKS_FAILED);
			  path=UtilConstants._VIEW_ALL_FEEDBACK;
		}
		  }
	  catch (NullPointerException e) {
		e.printStackTrace();
		path="ViewAllFeedBacks.jsp?status=Invalid Entries";
	}
    RequestDispatcher rd=request.getRequestDispatcher(path);
		rd.forward(request,response);

}


}
